<template>
  <div class="wrapper">
    <swiper :options="swiperOption" ref="mySwiper" v-if="showSwiper">
      <!-- slides -->
      <swiper-slide v-for="item in list" :key="item.id">
          <img class="swiper-img" :src="item.imgUrl" alt="">
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>

</template>

<script>
  export default {
    name: "HomeSwiper",
    props: {
      list: {
        type: Array,
        default: []
      }
    },
    computed: {
      /*
      * 因为list默认的是空数组，所以导致刚加载进来的时候从最后一张开始轮播
      * 让 swiper 的这个渲染是基于list有值的情况瞎来构建的，就能解决这个问题。
      *  这边的这个计算属性用来控制
      * */
      showSwiper () {
        return this.list.length
      }
    },
    data () {
      return {
        swiperOption: {
          pagination: '.swiper-pagination',
          loop: true // 循环轮播
        },

      }
    }
  }
</script>

<style scoped lang="stylus">
  .wrapper >>> .swiper-pagination-bullet-active
    background-color: #fff
  .wrapper
    width: 100%
    height: 0
    overflow: hidden
    padding-bottom: 31.25% // 宽高比，
    .swiper-img
      width: 100%
</style>
